package com.dcloud.streamweb.taskmanage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dcloud.streamweb.taskmanage.entity.SavepointBackup;
import com.dcloud.streamweb.taskmanage.mapper.SavepointBackupMapper;
import com.dcloud.streamweb.taskmanage.service.ISavepointBackupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;

/**
 * @Description: savepoint_backup
 * @Author: jeecg-boot
 * @Date:   2024-07-25
 * @Version: V1.0
 */
@Service
public class SavepointBackupServiceImpl extends ServiceImpl<SavepointBackupMapper, SavepointBackup> implements ISavepointBackupService {


    @Autowired
    private SavepointBackupMapper savepointBackupMapper;

    @Override
    public String getSavepointPathById(Long id, Long savepointId) {
        if(savepointId == null){
            return null;
        }
        SavepointBackup savepointBackup = savepointBackupMapper.selectOne(new LambdaQueryWrapper<SavepointBackup>().eq(SavepointBackup::getId, savepointId)
                .eq(SavepointBackup::getJobConfigId, id).eq(SavepointBackup::getIsDeleted, 0));
        if (savepointBackup != null) {
            return savepointBackup.getSavepointPath();
        }
        return null;
    }

    @Override
    public void insertSavepoint(Long jobConfigId, String savepointPath, Date backupTime) {
        SavepointBackup savepointBackup = new SavepointBackup();
        savepointBackup.setBackupTime(backupTime);
        savepointBackup.setSavepointPath(savepointPath);
        savepointBackup.setJobConfigId(jobConfigId);
        savepointBackupMapper.insert(savepointBackup);
    }
}
